/* rcctmtd.p - Checks specified Container structure for valid SO line items   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.3.1.2 $                                                         */
/*V8:ConvertMode=NoConvert                                                    */
/* REVISION: 8.5      LAST MODIFIED: 07/17/97   BY: *J1WM* Ajit Deodhar       */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* $Revision: 1.3.1.2 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*        */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}

/* INPUT PARAMETERS */
define input  parameter i_recid   as recid   no-undo.

/* OUTPUT PARAMETERS */
define output parameter err_flag  like mfc_logical initial false no-undo.

/* TEMP TABLES */
define temp-table t_done no-undo
   field t_recid as recid
   index t_recid is primary unique
   t_recid.

/* MAIN PROCEDURE BODY */

run ct_valid_line
   (input i_recid,
    output err_flag).

/* END OF MAIN PROCEDURE BODY */

/* INTERNAL PROCEDURES */

PROCEDURE ct_valid_line:
/*--------------------------------------------------------------------
  Purpose:     Recursively check the Container Structure
  Parameters:
       input:  i_recid   Record ID
      output:  err_flag  Logical indicating whether an error occurred
  Notes:
---------------------------------------------------------------------*/
   define input  parameter i_recid   as recid   no-undo.

   define output parameter err_flag  like mfc_logical initial false no-undo.

   /* BUFFERS */
   define buffer b1_abs_mstr for abs_mstr.
   define buffer b2_abs_mstr for abs_mstr.


   /* MAKE SURE THIS RECORD WASN'T ALREADY PROCESSED, */
   /* IN CASE OF CORRUPT CIRCULAR STRUCTURES */
   if can-find (t_done where t_recid = i_recid) then return.

   /* FLAG THAT THIS RECORD IS PROCESSED */
   create t_done.
   t_recid = i_recid.
   if recid(t_done) = -1 then .

   find first b1_abs_mstr where recid(b1_abs_mstr) = i_recid
   no-lock no-error.

   if available b1_abs_mstr then do:

      /* VALIDATE CONTAINER ITEMS THROUGH NESTED CONTAINERS */
      for each b2_abs_mstr where
            abs_shipfrom = b1_abs_mstr.abs_shipfrom and
            abs_par_id   = b1_abs_mstr.abs_id
      exclusive-lock:

         if abs_id begins "I" and
            not can-find (sod_det where sod_nbr = abs_order and
            sod_line = integer(abs_line))
         then
            err_flag = true.

         if abs_id begins "C" then
            run ct_valid_line
               (input recid(b2_abs_mstr),
                output err_flag).

         if err_flag then
            return.

      end.  /* FOR EACH B2_ABS_MSTR */

   end.  /* IF AVAILABLE B1_ABS_MSTR */

END PROCEDURE. /* CT_VALID_LINE */
